using System.Collections.Generic;
using Wombat.Core;
using Wombat.Core.Services;
using Wombat.Data.Model;

namespace Wombat.Data
{
    public class EntitiesFactory : IEntitiesFactory, IConfigurable, IInitializable
    {
        private static class ConfigurationKeys
        {
            public const string EntitiesConnectionString = "EntitiesConnectionString";
        }

        private readonly IConfigurationService _configurationService;
        private string _connectionString;

        public EntitiesFactory(IConfigurationService configurationService)
        {
            _configurationService = configurationService;
        }

        public WombatEntities Create()
        {
            return new WombatEntities(_connectionString);
        }

        public IDictionary<string, IConfigurationItem> Configurations { get; private set; }

        void IInitializable.Initialize()
        {
            Configurations = _configurationService.ReadConfigurations(GetType());
            _connectionString = (string)Configurations[ConfigurationKeys.EntitiesConnectionString].Value;
        }
    }
}